<?php
	/**
	* @File name:	catches.php
	* @Desription:	catchmodel
	* @Author:	 	jinxin<alucard.jx@gmail.com>   
	* @Date:	 	Mon Sep 05 17:48:48 CST 2011
	* @Copyright 	Copytright (c) jinxin<alucard.jx@gmail.com>
	* @version	 	$Id $
	*/
	
	class admin_animine_model_catches extends model {
		public function __construct(){
			parent::__construct();
		}
		
		public function test(){
			return $this->selectPage("SELECT * FROM animine_catch_list",1,30);
		}
		
		public function catching($type,$url,$title){
			switch ($type) {
				case 'youku':
					 $reg = '/id_(\d+).html/isU';
		                                        preg_match($reg,$url,$ret);
		                                        $plid = $ret[1];
		                                        $album_info = json_decode(file_get_contents("http://api.youku.com/api_ptplaylistinfo?rt=3&id={$plid}&pid=XMTI0OA=="));
		                                        $pages = ceil($album_info->item->videonum/100);
		                                        $vadios = array();
		                                        for ($page=1;$page<=$pages;$page++){
		                                                $tmp = json_decode(file_get_contents("http://api.youku.com/api_ptvideo/st_8?rt=3&sv={$plid}&pg={$page}&pz=100&od=1&pid=XMTI0OA=="));
		                                                foreach ($tmp->item as $value){
		                                                        $vadios[] = array(
		                                                                'title'                 => $value->title,
		                                                                'vid'                 => $value->videoid,
		                                                                'play_code'             => "http://player.youku.com/player.php/sid/{$value->videoid}/v.swf",
		                                                                'preview_img'   => $value->snapshot,
		                                                                'url'                   => $value->playurl,
		                                                                'createtime'    => $_SERVER['REQUEST_TIME']
		                                                        );
		                                                }
		                                        }
					break;
				case 'tudou':
					$txt = iconv($_SERVER['config']['catch']['tudou']['iconv'],'utf-8',file_get_contents($url));
					echo $txt;
					preg_match_all($_SERVER['config']['catch']['tudou']['regex'],$txt,$match);
					print_r($match);
					break;
				case 'sina':
					break;
				case '6cn':
					break;
				case 'qq':
					break;
			}
			return $vadios;
		}
		
		public function getCatchList($page,$pageszie){
			return $this->selectPage("SELECT * FROM animine_catch_list ORDER BY id DESC",$page,$pageszie);
		}
	}